package com.xiaoniu.douyinvideo.apps

import android.text.TextUtils
import org.jsoup.Jsoup

/**
 * @author zhaohe
 * @date 2021/3/26 15:11
 * @desc 快手app
 */
class GifMakerApp(var sourceUrl: String?) : VideoApp() {
    public override fun htmlUrl(): String? {
        return sourceUrl
    }

    public override fun parseHtml(htmlCode: String?): Pair<String, String>?? {
        if (TextUtils.isEmpty(htmlCode)) {
            return null
        }
        val document = Jsoup.parse(htmlCode)
        if (document == null) {
            return null
        }
        val videos = document.getElementsByClass("player-video")
        if (videos == null || videos.isEmpty()) {
            return null
        }
        val videoUrl = videos.get(0).attr("src") ?: ""
        if (TextUtils.isEmpty(videoUrl)) {
            return null
        }
        val realVideoUrl =  getRealUrl(videoUrl) ?: ""
        return Pair(videoUrl, realVideoUrl)
    }

    public override fun videoUrlTransform(videoUrl: String?): String? {
        return videoUrl
    }
}
